//
//  FocusDoctorViewController.m
//  QuickCure
//
//  Created by haoge on 16/9/10.
//  Copyright © 2016年 haoge. All rights reserved.
//

#define MAS_SHORTHAND
#define MAS_SHORTHAND_GLOBALS
static NSString * reuseId = @"doctor";

#import "FocusDoctorViewController.h"
#import "DocotorInfoViewController.h"
#import "NetWorkTool.h"
#import "DocotorDescribeCell.h"
#import "DoctorModel.h"
#import <Masonry.h>


@interface FocusDoctorViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView * tableView;
@property(nonatomic,strong)NSArray * doctorInfo;

@end


@implementation FocusDoctorViewController

-(NSArray *)doctorInfo{
    if (!_doctorInfo){
        
        NSDictionary *paramDic = @{@"ci1_id":@1,
                                   @"ci2_id":@3,
                                   @"ci3_id":@3,
                                   @"diagnosis_type":@0,
                                   @"page_size":@15,
                                   @"is_confirmed":@1,
                                   @"user_id":@1000089,
                                   @"page":@1,
                                   @"has_diagnosis":@2
                                   };
        

        [[NetWorkTool shareManager] POST_RequestWithUrlString:kMatchDoctors parmas:paramDic successBloock:^(id responseObject) {
            
            NSDictionary * dict = responseObject;
            _doctorInfo = dict[@"data"];
            
            NSMutableArray * array = [NSMutableArray arrayWithCapacity:20];
            
            for (int i=0; i<_doctorInfo.count; i++) {
                
                DoctorModel * model = [[DoctorModel alloc]initWithDict:_doctorInfo[i]];
                
                [array addObject:model];
            }
            
            _doctorInfo = (NSArray *)array;
            
            [self.tableView reloadData];
            
        } failureBlock:^(NSError *error) {
            
        }];
        

    
    }
    
    return _doctorInfo;
}

- (void)viewDidLoad {
    
    [super viewDidLoad];

    //tableView
    self.tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[DocotorDescribeCell class] forCellReuseIdentifier:@"cell"];
    self.tableView.backgroundColor = [UIColor colorWithRed:0.9511 green:0.9511 blue:0.9511 alpha:1.0];
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 100 ;

    [self.view addSubview:self.tableView];
  
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.equalTo(self.view);
        make.width.equalTo(self.view);
        
    }];
    
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.doctorInfo.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    DocotorDescribeCell * doc = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    doc.model = self.doctorInfo[indexPath.section];
    return doc;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    DocotorInfoViewController * vc =[[DocotorInfoViewController alloc]init];
    vc.title =@"医生基本信息";
    vc.model=self.doctorInfo[indexPath.section];
//    NSLog(@"%@",vc.model);
    [self.navigationController pushViewController:vc animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 15;
}

@end
